﻿Imports DTO
Imports System.Data.SqlClient


Public Class CTinhTrangNhanVienDAO
    Public Function LayDanhSachTinhTrangNhanVien() As List(Of CTinhTrangNhanVienDTO)
        Using cn As SqlConnection = CDataProvider.Connect()
            Dim cm As New SqlCommand("usp_LayDanhSachTinhTrangNhanVien", cn)
            cm.CommandType = CommandType.StoredProcedure
            Dim listttnv As New List(Of CTinhTrangNhanVienDTO)()
            Using reader As IDataReader = cm.ExecuteReader(CommandBehavior.CloseConnection)
                While reader.Read()
                    listttnv.Add(New CTinhTrangNhanVienDTO(reader))
                End While
            End Using
            Return listttnv
        End Using
    End Function

    Public Function ThemTinhTrangNhanVien(ByVal tentinhtrangnhanvien As String) As Integer
        Using cn As SqlConnection = CDataProvider.Connect()
            Dim cm As New SqlCommand("usp_ThemTinhTrangNhanVien", cn)
            cm.CommandType = CommandType.StoredProcedure
            Dim para As New SqlParameter("@tentinhtrangnhanvien", tentinhtrangnhanvien)
            cm.Parameters.Add(para)
            Dim parakq As New SqlParameter("@kt", 0)
            parakq.Direction = ParameterDirection.Output
            cm.Parameters.Add(parakq)
            cm.ExecuteNonQuery()
            Dim kq As Integer = Integer.Parse(cm.Parameters("@kt").Value.ToString())
            cn.Close()
            Return kq
        End Using
    End Function


    Public Function CapNhatTinhTrangNhanVien(ByVal tinhtrangnhanvien As CTinhTrangNhanVienDTO) As Integer
        Using cn As SqlConnection = CDataProvider.Connect()
            Dim cm As New SqlCommand("usp_CapNhatTinhTrangNhanVien", cn)
            cm.CommandType = CommandType.StoredProcedure
            Dim para As New SqlParameter("@matinhtrangnhanvien", tinhtrangnhanvien.Ma)
            cm.Parameters.Add(para)
            para = New SqlParameter("@tentinhtrangnhanvien", tinhtrangnhanvien.Ten)
            cm.Parameters.Add(para)
            Dim parakt As New SqlParameter("@kt", 0)
            parakt.Direction = ParameterDirection.Output
            cm.Parameters.Add(parakt)

            cm.ExecuteNonQuery()
            Dim kq As Integer = Integer.Parse(cm.Parameters("@kt").Value.ToString())
            cn.Close()
            Return kq
        End Using
    End Function


End Class
